<?php
class Controller_Test_Order extends Controller
{
    public function __construct ($request, $response)
    {
        parent::__construct($request, $response);
    }

    public function action_refund($orderNo)
    {
        $x = Order::refundSafety($orderNo);
    }

    public function action_sync_orders ()
    {
        $query = DB::select('id')
            ->from('mod_track')
            ->execute();

        foreach ($query as $rs)
        {
            $id = $rs['id'];
            $track = new App_Track($id);
            $track->updateCountsOrders();
        }

        $query = DB::select('id')
            ->from('mod_activity')
            ->execute();

        foreach ($query as $rs)
        {
            $id = $rs['id'];
            $track = new App_Activity($id);
            $track->updateCountsOrders();
        }
    }

    public function action_test($orderNo)
    {
        //$orderNo = '201508040001350000';
        App_Order::setOrderPaid($orderNo, 'testpaid'.time(), 2);
    }

    public function action_testShaiMoney()
    {
        $query = DB::select('orderNo')
            ->from('app_order')
            ->execute();

        foreach ($query as $rs)
        {
            $orderNo = $rs['orderNo'];
            $money   = App_Show_Config::getMoney($orderNo);

            echo "<p>$orderNo: $money</p>\n";
        }
    }

    public function action_shai ()
    {
        $query = DB::select()
            ->from('app_order_shai')
            ->where('orderNo', '<', 1000)
            ->or_where('moneyIncome', 'is', NULL)
            ->execute();

        foreach ($query as $rs)
        {
            $orderNo = $rs['orderNo'];
            $id      = $rs['id'];
            $orderNo = App_Order::getOrderNo($orderNo);
            $money   = App_Show_Config::getMoney($orderNo);
            DB::update('app_order_shai')
                ->set(array('orderNo' => $orderNo, 'moneyIncome' => $money))
                ->where('id', '=', $id)
                ->execute();
            echo "$id, $orderNo<br/>\n";
        }
    }
}
